package com.feiwo.nonego.rpc.protocol.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * RPC 通信类型枚举
 *
 * @author feiwo 2025-08-05
 */
public enum RpcType {
    // 请求
    REQUEST(1),
    // 响应
    RESPONSE(2),
    // 心跳
    HEARTBEAT(3);

    private final int type;

    RpcType(int type) {
        this.type = type;
    }

    private static final Map<Integer, RpcType> CACHE_MAP = new HashMap<>();
    static {
        for (RpcType value : values()) {
            CACHE_MAP.put(value.type, value);
        }
    }

    public static RpcType formType(int type) {
        return CACHE_MAP.get(type);
    }


    public int getType() {
        return type;
    }
}
